
#include <BStyle>
#include "member_BLabelItem.h"
#include "member_BGraphicWidget.h"
#include "member_BStyle.h"
#include "IGlobal.h"

using namespace BWE;

member_BLabelItem::member_BLabelItem(BLabelItem* labelItem)
{
	boss = labelItem;
	graph = Graph_None;
	dirty = true;
}
member_BLabelItem::~member_BLabelItem()
{

}

void member_BLabelItem::adjustRects(const BFont* font)
{
	const BStyle* style = boss->realStyle();
	block.text.reset();
	if (style)
		style->translate(text, block.text);
	if (block.text.empty() && text.size())
		block.text = text;
	block.reset();
	block.setStyle(style);
	block.font = font;
	block.adjust(0);
	alignment.ia_iconSize = imageSize;
	alignment.ia_textSize = block.size();

	BRectf crect = boss->centerRect();
	bool hasImage = image || graph;
	bool showImage = hasImage || (alignment.ia_form >= Form_IconOnly && alignment.ia_form <= Form_IconUnderText);
	if (alignment.ia_form == Form_IconAlone && !hasImage)
		showImage = false;
	if (alignment.ia_form == Form_TextAlone && text.empty() && hasImage)
		showImage = true;
	if (showImage)
	{
		if (image)
		{
			if (alignment.ia_iconSize.width() < 0)
				alignment.ia_iconSize.width() = (float)image->width();
			if (alignment.ia_iconSize.height() < 0)
				alignment.ia_iconSize.height() = (float)image->height();
		}
		if (font)
		{
			if (alignment.ia_iconSize.width() < 1)
				alignment.ia_iconSize.width() = (float)font->size();
			if (alignment.ia_iconSize.height() < 1)
				alignment.ia_iconSize.height() = (float)font->size();
		}
	}
	else
	{
		alignment.ia_iconSize.reset();
	}
	alignment.adjust(crect);
	block.setPos(alignment.ia_textRect.pos());
	hintSize = alignment.ia_hintSize;
}
